from core.basehandler import BaseHandler
from core.room import Room
from items.soda import Soda
from core.action import Action
from core.support import set_cutscene
from items.clothespin import Clothespin

class PrisonCell(Room):
    
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.canExit = False
        self.isFrigeUnlocked = False
        
        # build list of items
        self.add_item(Clothespin())
        
        # build list of actions
        self.add_action(OpenRefrigerator)
        self.add_action(ExitCell)
    
    def open_cell(self,b):
        self.canExit = b
    
    # return description of room.
    def get_description(self):
        return '''
        MacGyver awakens alone in a dirty prison cell.  He sees a refrigerator in the corner.  He is parched.
        '''
    # return image of room
    def get_image(self):
        return 'prison_cell.jpg'
     

class PrisonCellHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return PrisonCell

# define actions for this room

class OpenRefrigerator(Action):
    def __init__(self):
        Action.__init__(self, "open_refrigerator")    # do basic initialization for every action
        self.isOpen = False
    
    # this method gets called when action executed.  can be overridden in subclass
    def do_action(self,game,room,request):
        if room.isFrigeUnlocked:
            room.add_item(Soda())
            self.isOpen = True
            set_cutscene("MacGyver finds a refreshing can of Diet Tab in the refrigerator.")
        else:
            set_cutscene("Hmmm, the refrigerator is locked.")
        return
    
    # should this action be available to player?
    def is_enabled(self):
        return not self.isOpen
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Open Refrigerator"
    
    # if omitted in your action we return "post"
    def get_method(self):
        return "get"

class ExitCell(Action):
    def __init__(self):
        Action.__init__(self, "ExitCell")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Exit Cell"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'prisonhall'
    
    # should this action be available to player?
    def is_enabled(self):
        return self.room.canExit
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"